package com.pxxy.app_homepage.fragment;

import android.support.annotation.NonNull;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.pxxy.app_homepage.adapter.FragmentHomeHotRecyclerAdapter;
import com.pxxy.app_homepage.entity.Information;
import com.pxxy.lib_common.base.BaseFragment;
import com.pxxy.lib_common.entity.User;
import com.pxxy.security512.R;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

public class HomeHotFragment extends BaseFragment {
    private SmartRefreshLayout refreshLayout;
    private RecyclerView recyclerView;
    private List<Information> infoList;
    private FragmentHomeHotRecyclerAdapter adapter;
    @Override
    protected int setLayoutID() {
        return R.layout.homepage_fragment_home_hot;
    }

    @Override
    protected void initEvent() {
        //设置下拉刷新事件
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

            }
        });

        //设置上拉加载事件
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

            }
        });

        adapter = new FragmentHomeHotRecyclerAdapter(getActivity(),infoList);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(adapter);


    }

    @Override
    protected void initData() {
        infoList = new ArrayList<>();

        for (int i=0;i<10;i++){
            Information info = new Information();
            info.setId(i);
            List<String> list =new ArrayList<String>();
            list.add("http://120.77.205.137/back.jpg");
            info.setAddress(list);
            info.setSee(100);
            User user = new User();
            user.setName("中国消防");
            info.setTitle("吸客有道物美价廉 一个天河路商圈24个自创IP");
            info.setAuthor(user);

            infoList.add(info);
        }


    }

    @Override
    protected void initView(View view) {
        refreshLayout = view.findViewById(R.id.fragment_home_hot_refreshlayout);
        recyclerView = view.findViewById(R.id.fragment_home_hot_recycler);
    }
}
